/*
 * Copyright 2009 StructBeans Contributors
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
 * License for the specific language governing rights and limitations under 
 * the License.
 */

package org.structbeans.core;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * Provides lower level I/O methods
 *
 */
public class CInterOp {

        public static long readUnsignedInteger(DataInputStream in) throws IOException {

            long ui32 = in.read();
            long val = in.read();

            ui32 += val << 8;
            val = in.read();
            ui32 += val << 16;
            val = in.read();
            ui32 += val << 24;

            return ui32;
        }

        public static char readChar(DataInputStream in) throws IOException {
            return (char)in.readUnsignedByte();
        }

        public static char[] readCharArray(DataInputStream in, int size) throws IOException {
            char[] array = new char[size];

            for (int i = 0; i < size; i++) {
                array[i] = (char)in.readUnsignedByte();
            }

            return array;
        }

}
